package a07_二叉树;

//注意：
//     1
//         2
//       3    4
public class a11_二叉树的最小深度复习2 {
    public int minDepth(TreeNode root) {
        return getMinHeight(root);
    }

    private int getMinHeight(TreeNode node){
        if (node == null) {
            return 0;
        }
        int leftHeight = getMinHeight(node.left);
        int rightHeight = getMinHeight(node.right);
        if(leftHeight == 0){
            return rightHeight + 1;
        }
        if(rightHeight == 0){
            return leftHeight + 1;
        }
        return Math.min(leftHeight, rightHeight) + 1;
    }
}
